/*******************************************************************************
																				
	DESCRIPTION:  	This do file produces Figure A1.
	
*******************************************************************************/

clear all
global id_code 112

* Load 2006 holdout sample:
use if !missing(p_emplAft6M_0M_In) using "${data}/003_MainWithEnsemblePred_Full_2006.dta", ///
	clear

rename p_emplAft6M_0M_In p_emplAft6M_0M_In_B
	
* Merge with data on trainings
merge 1:1 Lop* InLnr using "${data}/005_UnemploymentCategoryStats", ///
	assert(2 3) keep(3) nogen

* Merge with predictions for the model without trainees:
merge 1:1 LopNr_PersonNr InLnr ///
	using "${data}/003_MainWithEnsemblePred_Full_NoTraining_2006.dta", ///
	keepusing(p_emplAft6M_0M_In) assert(3) keep(3) nogen

rename p_emplAft6M_0M_In p_emplAft6M_0M_In_NT
rename p_emplAft6M_0M_In_B p_emplAft6M_0M_In

* Set macros for graphs:
local months 6
local unempl 0
 
local l_any_training_combined "ALMPs (narrow)"
local l_any_ALMP "ALMPs (broad)"
local l_training_combined_6months "ALMPs (narrow) in First 6M" 
local l_ALMP_6months "ALMPs (broad) in First 6M"

local n_any_training_combined "ALMPs_Narrow"
local n_any_ALMP "ALMPs_Broad"
local n_training_combined_6months "ALMPs_Narrow_First6M" 
local n_ALMP_6months "ALMPs_Broad_First6M"
		
* Plot the density:
foreach pred in p_emplAft`months'M_`unempl'M_In p_emplAft`months'M_`unempl'M_In_NT {
	
	if "`pred'" == "p_emplAft6M_0M_In" {
		local mod
	}
	
	if "`pred'" == "p_emplAft6M_0M_In_NT" {
		local mod "_NoTraining"
	}
	
	
	foreach cond in  training_combined_6months ALMP_6months {
		
		* Kernel density plots:
		twoway ///
			(kdensity `pred', fcolor(ebblue%30) lcolor(ebblue) recast(area)) ///
			(kdensity `pred' if `cond'==1, recast(area) fcolor(orange_red%30) lcolor(orange_red)) ///
			, ///
			graphregion(color(white)) plotregion(margin(b=0 l=0))						///
			xtitle("Job-Finding Probability at Start of Spell (2006 Sample, Baseline Model)") ytitle("Density") 			///
			xscale(titlegap(2)) yscale(titlegap(2))	xlabel(0(0.1)1) ylabel(, angle(0) format(%9.0g)) ///
			legend(rows(1) order(1 "All" 2 "`l_`cond''") region(lwidth(none))) ///
			name(kdens_any, replace)

		graph export "${output}/${id_code}_Predicted6MJFR_Distribution_0M_ALMPS_Full`mod'_`n_`cond''_2006_kdensity.pdf", as(pdf) replace
	}
}